﻿using OPCTreeMonitor.InterfaceWindow;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace OPCTreeMonitor
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Initialize();
        }
   
        private void Initialize()
        {
            //读取配置
            OPCMethod.Instance.ReadConfig();
            //连接数据库
            OPCMethod.Instance.ConncetConfigDb();
            try
            {
                 OPCMethod.Instance.Connect();
            }
            catch (Exception ex)
            {

                MessageBox.Show("连接失败", ex.ToString());
            }

            OPCMethod.Instance.StartUpdate();
        }
        private void BtnRead_Click(object sender, RoutedEventArgs e)
        {
            var td = OPCMethod.Instance.GetPlcByIndex(0).ReadData("ns=3;s=\"输出信号\".\"1#声光报警之红灯\"");

            ceshiRead.Content = td.ToString();
        }
        private PLCInterface window1;
        private void Btn_WindowClick(object sender, RoutedEventArgs e)
        {
            if (window1 == null)
            {
                window1 = new PLCInterface();
                window1.Closed += (s, e) => window1 = null; // 当窗口关闭时重置实例
                window1.Topmost = true;
                window1.Show();
            }
            else
            {
                window1.WindowState = WindowState.Normal;
                window1.Activate();
            }
        }


      
    }
}